package Controlador;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import Modelo.ModIngredientes;

public class ContIngredientes {
	
	public void limpiar(JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		jTextField1.setText("");
		jTextField2.setText("");
		jTextField3.setText("");
		jButton1.setEnabled(false);
		jButton2.setEnabled(false);
		jButton3.setEnabled(false);	
		jTextField1.setEnabled(true);
	}
	public void eliminar(JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		if (JOptionPane.showConfirmDialog(null, "Esta seguro")==JOptionPane.YES_OPTION)
		{
			ModIngredientes tIngredientes = new ModIngredientes();			
			tIngredientes.Eliminar("\"CodIngre\"="+jTextField1.getText()+"");
			JOptionPane.showMessageDialog(null, "Eliminado");
			limpiar(jTextField1, jTextField2, jTextField3, jButton1, jButton2, jButton3);
		}
	}
	public void guardar(JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		ModIngredientes tIngredientes = new ModIngredientes();
		tIngredientes.setCodIngre(Integer.parseInt(jTextField1.getText()));
		tIngredientes.setDescripcion(jTextField2.getText());
		tIngredientes.setCantidad(Double.parseDouble(jTextField3.getText()));
		tIngredientes.guardar();
		JOptionPane.showMessageDialog(null, "Actualizacion Completa");
		limpiar(jTextField1, jTextField2, jTextField3, jButton1, jButton2, jButton3);
	}
	void mostrar(ModIngredientes t,JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		jTextField1.setText(""+t.getCodIngre());
		jTextField2.setText(""+t.getDescripcion());
		jTextField3.setText(""+t.getCantidad());
		jButton1.setEnabled(false);
		jButton2.setEnabled(true);
		jButton3.setEnabled(true);					
		jTextField1.setEnabled(false);
	}

	public void buscar(JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		ModIngredientes tIngredientes = new ModIngredientes();
		tIngredientes.Cargar("\"CodIngre\"="+jTextField1.getText()+"");
		if (tIngredientes.getEncontro())
			mostrar(tIngredientes,jTextField1, jTextField2, jTextField3, jButton1, jButton2, jButton3);
		else
		{
			String aux=jTextField1.getText();
			limpiar(jTextField1, jTextField2, jTextField3, jButton1, jButton2, jButton3);
			jTextField1.setText(aux);
			jButton1.setEnabled(true);
		}

	}

	
}
